//智能api接口相关
const config=require('./config')
const Wechat=require('./vchat').Wechat
const api={
    //语义，需认证公众号才能用，测试号要公众号平台后台开启否则报错
    semantic:'https://api.weixin.qq.com/semantic/semproxy/search?',
    //提交语音做语音识别，该功能已废弃，公众号后台开启语音结果就会多一个识别结果的属性
    addVoice:'http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?',
}

let chat=new Wechat(config.wechat)
exports.intelligence= {
    intelligenceOpt: async (dataType,postData) => {
        let url = ''
        let body = null;
        switch (dataType) {
            case 'semantic':
                url=api.semantic
                body={
                    "query":postData.query,
                    "city":postData.city,
                    "category": "flight",
                    "uid":postData.uid,
                    "appid":chat.appID
                }
                break;

        }
        return chat.getAcc().then(data=>{
            url+=`access_token=${data.access_token}`;
            console.log(body)
            return chat.getBody({url:url,method:'POST',body:body,json:true})
        })
    }
}